#include <bits/stdc++.h>
using namespace std;

void show(int m, int n, int x[m][n])
{
    cout << "矩阵:" << endl;
    for(int i=0; i<m; i++)
    {
        for(int j=0; j<n; j++)
            cout << x[i][j] << " ";
        cout << endl;
    }

}

int main(int argc, char const *argv[])
{
    // 输入矩阵A
    int m, n;
    cin >> m >> n;

    int A[m][n];
    for(int i=0; i<m; i++)
    {
        for(int j=0; j<n; j++)
            cin >> A[i][j];
    }
    show(m, n, A);

    int r, s;
    cin >> r >> s;

    int B[r][s];
    for(int i=0; i<r; i++)
    {
        for(int j=0; j<s; j++)
            cin >> B[i][j];
    }
    show(r, s, B);

    // 构造子矩阵C
    int C[r][s];
    int absSum;
    int minSum=INT_MAX, p=0, q=0;

    for(int p1=0, q1=0; p1<=n-r&&q1<=m-s ;p1++, q1++)
    {
        bzero(C, sizeof(C));

        int p2 = p1;
        int q2 = q1;
        for (int i = 0; i < r; i++, p2++)
        {
            for (int j = 0; j < s; j++, q2++)
                C[i][j] = A[p2][q2];
        }

        absSum = 0;
        for (int i = 0; i < r; i++)
        {
            for (int j = 0; j < s; j++)
                absSum += abs(C[i][j] - B[i][j]);
        }
        cout << "absSum:" << absSum << endl;
        cout << "minSum:" << minSum << endl;

        if(absSum < minSum)
        {
            p = p1;
            q = q1;
        }
    }

    // 输出A[p][q] ~ A[p+r][q+s]
    for(int i=p; i<p+r; i++)
    {
        for(int j=q; j<q+s; j++)
            cout << A[i][j] << " ";
        cout << endl;
    }

    return 0;
}
